package com.sanrenzu.everybodytv.ui.vertical.colum;

import android.nfc.tech.Ndef;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;

import com.sanrenzu.everybodytv.bean.zxb.VideoItemBean;
import com.sanrenzu.everybodytv.bean.zxb.VideoItemChildBean;

import java.util.List;
import java.util.Map;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by My on 2016/9/6.
 */
public class ColumItemPresenter implements ColumItemContract.Presenter{

    private ColumItemContract.View view;
    private ColumItemContract.Modle modle;

    public ColumItemPresenter(ColumItemContract.View view){
        this.view =view;
        modle= new ColumItemModle();
    }

    @Override
    public void onGetVideoItem(String name) {
        modle.onGetVideoItemBean(name, new Callback<VideoItemBean>() {
            @Override
            public void onResponse(Call<VideoItemBean> call, Response<VideoItemBean> response) {
                 VideoItemBean bean = response.body();
                final List<VideoItemChildBean> data = bean.getData();
                Log.i("TAG", "===>>onResponse: "+data.size());
                Handler handler = new Handler(Looper.getMainLooper());
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        view.onGetVideoItemChildBean(data);
                    }
                });
            }

            @Override
            public void onFailure(Call<VideoItemBean> call, Throwable t) {
                Handler handler = new Handler(Looper.getMainLooper());
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        view.onGetVideoItemBeanFailed("网络获取失败");
                    }
                });
            }
        });
    }
}
